package com.cnfangmao.masterdata.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cnfangmao.masterdata.common.response.ResBody;
import com.cnfangmao.masterdata.common.response.ResCodeEnum;
import com.cnfangmao.masterdata.common.util.UserUtils;
import com.cnfangmao.masterdata.model.BasicDataMetadata;
import com.cnfangmao.masterdata.service.AccountBasicDataRightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @description: 首页控制器   
 * @author:	chenxc   
 * @date:   2020年4月20日 下午5:06:49
 */
@Api(tags = "0-1、首页-首页")
@RequestMapping(path = "/home")
@RestController
public class HomeController {

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

	@Autowired
	private AccountBasicDataRightService accountBasicDataRightService;
	
	/**
	 * @description: 获取当前账号有权限的主数据列表 
	 * @author: chenxc
	 * @date: 2020年4月20日 下午5:07:32
	 * @param: @return      
	 * @return: ResBody      
	 * @throws
	 */
	@ApiOperation(value = "获取当前账号有权限的主数据列表", notes = "获取当前账号有权限的主数据列表")
	@GetMapping(path = "/get-auth-masterdata.do")
	public ResBody<List<BasicDataMetadata>> getAuthMasterdata() {
		try{
			List<BasicDataMetadata> listBasicDataMetadata = accountBasicDataRightService.getMasterdataByUserId(UserUtils.getUserId());
			return new ResBody<List<BasicDataMetadata>>(ResCodeEnum.SUCCESS.getCode(), "", listBasicDataMetadata);
			
		}catch(Exception ex){
			logger.error(String.format("run getAuthMasterdata error: %s", ex.getMessage()));
			return new ResBody<List<BasicDataMetadata>>(ResCodeEnum.FAIL.getCode(), ex.getMessage(), null);
		}
	}
}
